cmake_minimum_required(VERSION 3.10)

project(tokenizer)

add_library(tokenizer SHARED
    tokenizer.cpp
)

set(SPM_ENABLE_SHARED OFF)  # build sentencepiece as static library only
add_subdirectory(third_party/sentencepiece EXCLUDE_FROM_ALL)

target_link_libraries(tokenizer PRIVATE sentencepiece)
target_include_directories(tokenizer PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}/include
    third_party/sentencepiece/src
)

add_executable(main main.cpp)
target_link_libraries(main PRIVATE tokenizer)
target_include_directories(main PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}/include
    # this is needed since we include <sentencepiece_processor.h> in tokenizer.hpp!!!
    third_party/sentencepiece/src
)

# installation setup
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Install path prefix" FORCE)

install(TARGETS tokenizer
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib
)
install(DIRECTORY include/ DESTINATION include)
install(TARGETS main
    RUNTIME DESTINATION bin
)
